package com.fanpan26.aop.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author fanpan26
 */
public class MyInvocationHandler implements InvocationHandler {



    private Man man;

    public MyInvocationHandler(Man man) {
        this.man = man;
    }

    public Man getProxy() {
//        return (Man) Proxy.newProxyInstance(man.getClass().getClassLoader(),
//                man.getClass().getInterfaces(), this);
        return (Man) Proxy.newProxyInstance(Man.class.getClassLoader(),
              new Class[]{  Man.class}, this);

    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before");
        //method.invoke(man, args);
        System.out.println("this is prxy method");
        System.out.println("after");
        return null;
    }
}
